package at.fhj.itm11.forum.util;

import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Inject;

import at.fhj.itm11.forum.data.IconRepository;
import at.fhj.itm11.forum.model.Icon;

@ManagedBean
public class IconConverter implements Converter {

	@Inject
	private IconRepository iconRepository;
	
	
	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		return iconRepository.findIconById(Long.valueOf(arg2));
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		return String.valueOf(((Icon)arg2).getId());
	}

}
